package web.controller.sys;

import com.github.pagehelper.PageInfo;
import framework.vo.ResultInfo;
import framework.vo.ResultList;
import io.swagger.annotations.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import system.entity.SysLoginFailLimit;
import system.service.sys.SysLoginFailLimitService;

@RestController
@RequestMapping("/sys/login/fail/limit")
@Api(tags = "登录记录")
public class SysLoginFailLimitController {
    @Autowired
    private SysLoginFailLimitService sysLoginFailLimitService;

//    @ApiOperation("添加登录失败限制")
//    @PostMapping("/add")
//    public ResultInfo<String> add(@ModelAttribute SysLoginFailLimit param) {
//        java.util.Date now = new java.util.Date();
//        param.setCreateTime(now);
//        Integer added = sysLoginFailLimitService.add(param);
//        ResultInfo<String> info = new ResultInfo<>(param.getUsername());
//        return info;
//    }

    @ApiOperation("删除登录失败限制")
    @PostMapping("/del")
    public ResultInfo<Integer> del(@RequestParam("ids") List<String> ids) {
        Integer deleted = sysLoginFailLimitService.deleteByIds(ids);
        ResultInfo<Integer> info = new ResultInfo<>(deleted);
        return info;
    }

//    @ApiOperation("更新登录失败限制")
//    @PostMapping("/edit")
//    public ResultInfo<Integer> edit(@ModelAttribute SysLoginFailLimit param) {
//        java.util.Date now = new java.util.Date();
//        Integer updated = sysLoginFailLimitService.update(param);
//        ResultInfo<Integer> info = new ResultInfo<>(updated);
//        return info;
//    }

    @ApiOperation("查看登录失败限制")
    @GetMapping("/info")
    public ResultInfo<SysLoginFailLimit> info(@RequestParam("id") String id) {
        SysLoginFailLimit info = sysLoginFailLimitService.loadById(id);
        return new ResultInfo<>(info);
    }

    @ApiOperation("登录失败限制列表")
    @GetMapping("/list")
    public ResultList<SysLoginFailLimit> list(SysLoginFailLimit param, @RequestParam(value = "pageIndex", defaultValue = "1") Integer pageIndex, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageInfo<SysLoginFailLimit> info = sysLoginFailLimitService.list(param, pageIndex, pageSize);
        return new ResultList<>(info);
    }
}